package cn.hk.vaccination.service.impl;

import cn.hk.vaccination.domain.SubscribeDetail;
import cn.hk.vaccination.domain.SubscribeSetting;
import cn.hk.vaccination.mapper.SubscribeDetailMapper;
import cn.hk.vaccination.mapper.SubscribeSettingMapper;
import cn.hk.vaccination.service.SubscribeDetailService;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 预约设置明细表（各种时间段放号数） 服务实现类
 * </p>
 *
 * @author xu
 * @since 2023-03-23
 */
@Service
public class SubscribeDetailServiceImpl extends ServiceImpl<SubscribeDetailMapper, SubscribeDetail> implements SubscribeDetailService {
    @Autowired
    private SubscribeSettingMapper subscribeSettingMapper;
    @Autowired
    private SubscribeDetailMapper subscribeDetailMapper;
    @Override
    public List<SubscribeDetail> selectListByDeptId(Long deptId) {
        SubscribeSetting subscribeSetting = subscribeSettingMapper.selectOneByDeptId(deptId);
        if (ObjectUtil.isNotNull(subscribeSetting)){
            List<SubscribeDetail> subscribeDetailList = subscribeDetailMapper.selectListBySubscribeSettingId(subscribeSetting.getId());
            for (SubscribeDetail subscribeDetail : subscribeDetailList) {
                //设置可提前预约的天数
                subscribeDetail.setAdvanceYyTime(subscribeSetting.getAdvanceYyTime());
            }
            return subscribeDetailList;
        }
        return null;
    }

    @Override
    public SubscribeDetail getOneById(Long Id) {
        return subscribeDetailMapper.selectOneById(Id);
    }

    @Override
    public Boolean editById(SubscribeDetail subscribeDetail2AmValue) {
        return subscribeDetailMapper.updateOneById(subscribeDetail2AmValue);
    }
}
